class AlbumsController < ApplicationController

  before_filter :load_member
  
  def initialize
    @styleName = "my_photo"
  end
  # GET /albums
  # GET /albums.xml
  def index
    @albums = Album.paginate_by_accounts_id params[:member_id], :page => params[:page]
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @albums }
    end
  end

  def new
    @album = Album.new
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @albums }
    end
  end
  # GET /albums/1
  # GET /albums/1.xml
  def show
    @album = Accounts.find(params[:member_id]).find params[:id]
  end

  # GET /albums/1/edit
  def edit
    @album = Album.find params[:id]
  end

  # POST /albums
  # POST /albums.xml
  def create
    @album = current_accounts.albums.build(params[:album])

    respond_to do |format|
      if @album.save
        flash[:notice] = 'Album was successfully created.'
        format.html { redirect_to :action => "index" }
        format.xml  { render :xml => @album, :status => :created, :location => @album }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @album.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /albums/1
  # PUT /albums/1.xml
  def update
    @album = Album.find(params[:id])

    respond_to do |format|
      if @album.update_attributes(params[:album])
        flash[:notice] = 'Album was successfully updated.'
        format.html { redirect_to(@album) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @album.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /albums/1
  # DELETE /albums/1.xml
  def destroy
    @album = Album.find(params[:id])
    @album.destroy

    respond_to do |format|
      format.html { redirect_to(albums_url) }
      format.xml  { head :ok }
    end
  end

  protected

  def load_member
    @member = Member.find params[:member_id]
  end

end
